package com.zzyl.serve.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.NursingProject;
import com.zzyl.serve.service.INursingProjectService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 护理项目Controller
 *
 * @author ruoyi
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/serve/project")
@Api(value = "护理项目管理", tags = {"护理项目"})
public class NursingProjectController extends BaseController
{
    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('serve:project:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询护理项目列表", notes = "根据条件查询护理项目的列表信息")
    public TableDataInfo list(
            @ApiParam(name = "nursingProject", value = "用于过滤的护理项目对象", required = false) NursingProject nursingProject)
    {
        startPage();
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    /**
     * 导出护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('serve:project:export')")
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出护理项目列表", notes = "导出所有或指定条件下的护理项目数据到Excel文件")
    public void export(
            HttpServletResponse response,
            @ApiParam(name = "nursingProject", value = "用于过滤的护理项目对象", required = false) NursingProject nursingProject)
    {
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        ExcelUtil<NursingProject> util = new ExcelUtil<>(NursingProject.class);
        util.exportExcel(response, list, "护理项目数据");
    }

    /**
     * 获取护理项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('serve:project:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取护理项目详细信息", notes = "通过ID获取护理项目的详细信息")
    public AjaxResult getInfo(
            @ApiParam(name = "id", value = "护理项目的唯一标识符", required = true, example = "1") @PathVariable("id") Long id)
    {
        return success(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 新增护理项目
     */
    @PreAuthorize("@ss.hasPermi('serve:project:add')")
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增护理项目", notes = "创建一个新的护理项目")
    public AjaxResult add(
            @ApiParam(name = "nursingProject", value = "要创建的护理项目对象", required = true) @RequestBody NursingProject nursingProject)
    {
        return toAjax(nursingProjectService.insertNursingProject(nursingProject));
    }

    /**
     * 修改护理项目
     */
    @PreAuthorize("@ss.hasPermi('serve:project:edit')")
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改护理项目", notes = "更新已存在的护理项目的信息")
    public AjaxResult edit(
            @ApiParam(name = "nursingProject", value = "包含更新信息的护理项目对象", required = true) @RequestBody NursingProject nursingProject)
    {
        return toAjax(nursingProjectService.updateNursingProject(nursingProject));
    }

    /**
     * 删除护理项目
     */
    @PreAuthorize("@ss.hasPermi('serve:project:remove')")
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除护理项目", notes = "批量删除护理项目")
    public AjaxResult remove(
            @ApiParam(name = "ids", value = "要删除的护理项目的ID数组", required = true, allowMultiple = true, example = "1,2,3") @PathVariable Long[] ids)
    {
        return toAjax(nursingProjectService.deleteNursingProjectByIds(ids));
    }
}